const axios = require("axios");
axios.default.interceptors.request.use(
    config => {
        let url = config.url;
        // get参数进行百分比编码
        if (config.method === "get" && config.params) {
            url += "?";
            let keys = Object.keys(config.params);
            for (let key of keys) {
                url += `${key}=${encodeURIComponent(config.params[key])}&`;
            }
            url = url.substring(0, url.length - 1);
            config.params = {};
        }
        config.url = url;
        return config;
    },
    function(error) {
        return Promise.reject(error);
    }
);
const get = function(url, config) {
    return axios.get(url, config).then(response => {
        const { data, status, statusText } = response;
        if (status == 200 || status == 304) {
            return data;
        } else {
            throw new Error(statusText);
        }
    });
};
//获取电影详情信息
export const getmovieinfo = function () {
    return get('/mock/detailMovie.json')
}
//获取电影信息
export const getmovie = function () {
    return get('/mock/movie.json')
}
//获取全部，品牌信息
export const moviefilter = function () {
    return get('/ajax/filterCinemas')
}